package com.app.newiptv.adaper;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.app.newiptv.R;
import com.app.newiptv.bean.ChannelType;
import com.app.newiptv.callback.OnItemClickListener;
import com.app.newiptv.utils.APPLog;
import com.bumptech.glide.Glide;

import java.util.List;


/**
 * Created by wendal on 2017/9/23.
 */

public class HomeChannelTypesAdapter extends RecyclerView.Adapter<HomeChannelTypesAdapter.MyViewHolder> {
    private int count;
    private RecyclerView parentRecycle;
    private Context context;
    private View focusview;
    private OnItemClickListener listener;
    public ChannelType.DataBean currentChannl;
    private List<ChannelType.DataBean> channels;
    public HomeChannelTypesAdapter(List<ChannelType.DataBean> channels, Context context, View focusview) {
        this.channels = channels;
        this.context = context;
        this.focusview = focusview;
    }
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }
    public void setCount(int count) {
        this.count = this.channels.size();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.home_channel_type_item, null);
        final MyViewHolder viewHolder = new MyViewHolder(view);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                currentChannl = channels.get(viewHolder.position);
                listener.onItemClick(v);
            }
        });
        if (parentRecycle == null) {
            parentRecycle = (RecyclerView) parent;
        }
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.setPosition(position);
        holder.bottom_text.setText(channels.get(position).getT_name());

        APPLog.printInfo(count + "onBindViewHolder" + position);
    }

    @Override
    public int getItemCount() {
        return channels.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private int position;
        private TextView bottom_text;
        private LinearLayout bottom_layout;
        public MyViewHolder(View itemView) {
            super(itemView);
            bottom_text = (TextView) itemView.findViewById(R.id.home_channle_type_name);
            bottom_layout = (LinearLayout) itemView.findViewById(R.id.home_channle_type_layout);
            itemView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View view, boolean b) {
                    if (b) {
                        view.bringToFront();
                        view.animate().scaleX(1.50f);
                        view.animate().scaleY(1.50f);
//                        bottom_layout.setBackgroundResource(R.mipmap.bg_pic_s);
                    } else {
                        view.animate().scaleX(1.0f);
                        view.animate().scaleY(1.0f);
//                        bottom_layout.setBackgroundResource(0);
                    }
                }
            });
            itemView.setOnClickListener(new SetOnClick());
        }

        public void setPosition(int position) {
            this.position = position;
        }


        class SetOnClick implements View.OnClickListener {

            @Override
            public void onClick(View v) {
            }
        }
    }
}
